package cn.tedu.property2022.controller;

import cn.tedu.property2022.pojo.dto.AnnouncementsAddNewDTO;
import cn.tedu.property2022.pojo.vo.AnnouncementsLsitVO;
import cn.tedu.property2022.pojo.vo.AnnouncementsVO;
import cn.tedu.property2022.service.IAnnouncementsService;
import cn.tedu.property2022.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/ann")
public class AnnouncementsContorller {

    @Autowired
    IAnnouncementsService announcementsService;

    @GetMapping("/get/{title}")
    @ApiOperation("根据公告标题查询公告")
    public JsonResult<List<AnnouncementsVO>>getAnnouncements(@PathVariable String title){
        List<AnnouncementsVO> annoucements = announcementsService.Annoucements(title);
        return JsonResult.ok(annoucements);
    }
    @GetMapping("/list")
    @ApiOperation("查询所有公告")
    public JsonResult<List<AnnouncementsLsitVO>>ListAnnouncements(){
        List<AnnouncementsLsitVO> announcementsLsitVOS = announcementsService.list();
        return JsonResult.ok(announcementsLsitVOS);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据告id查询详情")
    public JsonResult<List<AnnouncementsVO>>get(@PathVariable Long id){
        List<AnnouncementsVO> message = announcementsService.getMessage(id);
        return JsonResult.ok(message);
    }
    @PostMapping("/add")
    @ApiOperation("发布公告")
    public JsonResult<Void>add(@Validated AnnouncementsAddNewDTO  announcementsAddNewDTO){
        announcementsService.addNew(announcementsAddNewDTO);
        return JsonResult.ok();
    }

}
